翻訳と辞書
Words near each other
・ Maximum safe storage temperature
・ Maximum satisfiability problem
・ Maximum score estimator
・ Maximum Security
・ Maximum Security (Alien Sex Fiend album)
・ Maximum Security (comics)
・ Maximum Security (novel)
・ Maximum Security (Tony MacAlpine album)
・ Maximum Security (TV series)
・ Maximum security prison
・ Maximum segment lifetime
・ Maximum segment size
・ Maximum Shame
・ Maximum spacing estimation
・ Maximum Strength
Maximum subarray problem
・ Maximum Surge
・ Maximum sustainable yield
・ Maximum sustained wind
・ Maximum takeoff weight
・ Maximum term method
・ Maximum the Hormone
・ Maximum the Hormone discography
・ Maximum theorem
・ Maximum throughput scheduling
・ Maximum time aloft
・ Maximum time in grade
・ Maximum time interval error
・ Maximum tolerable period of disruption
・ Maximum Trance


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Maximum subarray problem : ウィキペディア英語版
Maximum subarray problem
In computer science, the maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers (containing at least one positive number) which has the largest sum. For example, for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6.
The problem was first posed by Ulf Grenander of Brown University in 1977, as a simplified model for maximum likelihood estimation of patterns in digitized images. A linear time algorithm was found soon afterwards by Jay Kadane of Carnegie-Mellon University .
==Kadane's algorithm==
Kadane's algorithm consists of a scan through the array values, computing at each position the maximum (positive sum) subarray ending at that position. This subarray is either empty (in which case its sum is zero) or consists of one more element than the maximum subarray ending at the previous position. Thus, the problem can be solved with the following code, expressed here in Python:

def max_subarray(A):
max_ending_here = max_so_far = 0
for x in A:
max_ending_here = max(0, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far

A variation of the problem that does not allow zero-length subarrays to be returned, in the case that the entire array consists of negative numbers, can be solved with the following code:

def max_subarray(A):
max_ending_here = max_so_far = A()
for x in A():
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far

The algorithm can also be easily modified to keep track of the starting and ending indices of the maximum subarray.
Because of the way this algorithm uses optimal substructures (the maximum subarray ending at each position is calculated in a simple way from a related but smaller and overlapping subproblem: the maximum subarray ending at the previous position) this algorithm can be viewed as a simple example of dynamic programming.
The runtime complexity of Kadane's algorithm is O(n).

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Maximum subarray problem」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.